package primary.util;

import primary.code04_List.Node;
import primary.code04_List.RandomNode;

public class ListUtils {
    public static String printList(Node head) {
        if (head == null) {
            return null;
        }
        StringBuilder sbResult = new StringBuilder();
        Node temp = head;
        while (temp != null) {
            sbResult.append(temp.data + "-->");
            temp = temp.next;
        }
        return sbResult.toString();
    }

    public static String printList(RandomNode head) {
        if (head == null) {
            return null;
        }
        StringBuilder sbResult = new StringBuilder();
        RandomNode temp = head;
        while (temp != null) {
            String random = temp.random == null ? "" : "(" + temp.random.data + ")";
            sbResult.append(temp.data + random + "-->");
            temp = temp.next;
        }
        return sbResult.toString();
    }
}
